<?php

/**
 * 
 * ============================================================================
 * 
 * 
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 
 * Date: 
 */

namespace Home\Controller;

use Home\Logic\ArticleLogic;

class ArticleController extends BaseController {

    public function index() {
        $article_id = I('article_id', 1);
        $article = D('article')->where("article_id=$article_id")->find();
        if ($article) {
            $parent = D('article_cat')->where("cat_id=" . $article['cat_id'])->find();
            $this->assign('cat_name', $parent['cat_name']);
            $this->assign('article', $article);
        }
        $this->display();
    }

    /**
     * 文章内列表页
     */
    public function articleList() {
        $article_cat = M('ArticleCat')->where("parent_id  = 0")->select();
        $this->assign('article_cat', $article_cat);
        $this->display();
    }

    /**
     * 文章内容页
     */
    public function detail() {
        $article_id = I('article_id', 1);
        $article = D('article')->where("article_id=$article_id")->find();
        if ($article) {
            $parent = D('article_cat')->where("cat_id=" . $article['cat_id'])->find();
            $this->assign('cat_name', $parent['cat_name']);
            $this->assign('article', $article);
        }
        $this->display();
    }

    /**
     * ajax用户消息通知请求
     * @author dyr
     * @time 2016/09/01
     */
    public function inbox()
    {
        $user_sys_message = D('Message')->getUserMessageNotice();
        $this->assign('messages', $user_sys_message);
        $this->display();
    }

    /*
     * 会员删除收到的信件
     */
    public function del_user_message()
    {
        $res = M('user_message')->where(array('rec_id'=>$_GET['id']))->save(array('status'=>2));
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败，请稍后重试');
        }
    }

    /*
     * 会员发送邮件
     */
    public function sendemail(){
        if(IS_POST){
            $data['u_id'] = $_SESSION['user']['user_id'];
            $data['zf_time'] = time();
            $data['title'] = $_POST['title'];
            $data['content'] = $_POST['content'];
            $res = M('article_message')->add($data);
            if($res){
                $this->success('操作成功，等待管理员查看');
            }else{
                $this->error('操作失败，请稍后再试');
            }
        }else{
            $this->display();
        }
    }

    /*
     * 会员已发邮件列表
     */
    public function outbox()
    {
        if(!empty($_POST['title'])){
            $map['title'] = array('like','%'.$_POST['title'].'%');
        }
        if(!empty($_POST['type'])){
            $map['type'] = $_POST['type'];
        }
        $map['u_id'] = $_SESSION['user']['user_id'];
        $this->list =M('article_message')->where($map)->select();
        $this->display();
    }


    public function replydetail() {
        $article_id = I('id', 1);
        $article = D('article_message')->where("id=$article_id")->find();
        if ($article) {
            $this->assign('list', $article);
        }
        $this->display();
    }

}
